/***** BEGIN LICENSE BLOCK *****
Copyright the original author Andy Shaules ( bowljoman AT hotmail DOT com) thebitstream.com
Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
	http://www.mozilla.org/MPL/MPL-1.1.html
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

# ***** END LICENSE BLOCK *****/
package sandy.redSandy
{
	import flash.net.NetConnection;
	import mx.utils.StringUtil;
	import flash.net.NetStream;
	import flash.net.SharedObject;
	import flash.net.Responder;
	/**
	 * 
	 * @author Andy Shaules
	 * 
	 */	
	public class RedSandy
	{
		
		private var _connector:RedSandyConnector;
		private var _client:Object;
		private var _connectionEvents:Connection=new Connection();
		
		public function get clientData():Object
		{
			return _connector.clientData;
		}
		public function RedSandy()
		{
			_connector=new RedSandyConnector();
			_connector.dispatcher=_connectionEvents;
		}
		public function connect(uri:String,...parameters):void
		{
			_connector.connect(uri,parameters);
		}
		public function createNetstream():NetStream
		{
			return new NetStream(_connector);
		}
		public function createSharedObject(pName:String,persistance:Boolean=false,secure:Boolean=false):SharedObject
		{
			return SharedObject.getRemote(pName,_connector.uri,persistance,secure);			
		}
		public function connectSharedObject(obj:SharedObject,params:String=null):void
		{
			obj.connect(_connector,params);
		}
		public function get netConnectionEvents():Connection
		{
			return _connectionEvents;
		}
		public function getAllProperties(callBack:Function=null):void
		{
			_connector.getAllProperties(callBack);
		}
		public function setProperty(key:String,value:Object,callBack:Function=null):void
		{
			_connector.setProperty(key,value,callBack);
		}
		public function getProperty(key:String,callBack:Function):void
		{
			_connector.getProperty(key,callBack);
		}
		public function getUserProperty(user:String,key:String,callBack:Function):void
		{
			_connector.getUserProperty(user,key,callBack);
		}
		public function sendEvent(data:Object):void
		{
			_connector.sendEvent(data);		
		}
		public function set client(object:IRedSandy):void
		{
			_client=object;
			
			_connector.sandyClient=object;
		}
		public function get client():IRedSandy
		{
			if(_connector.client is RedSandyConnector)
			return null;
			else
			return _connector.client as IRedSandy;
		}
		public function resetConnection():void
		{
			_connector.close();
			_connector=new RedSandyConnector();
			if(_client)
			_connector.client=_client;
		}

	}
}